#include "Vector.h"
#include <iostream>
#include <cmath>

using namespace std;

Vector::Vector (const Point &p1, const Point &p2)
{
	x = p2.get_x() - p1.get_x();
	y = p2.get_y() - p1.get_y();
	z = p2.get_z() - p1.get_z();
	t = 0.0;
}

Vector Vector::operator^(const Vector &v1) const
{
	Vector v = Vector();
	v.set_x((get_y() * v1.get_z()) - (get_z() * v1.get_y()));
	v.set_y((get_z() * v1.get_x()) - (get_x() * v1.get_z()));
	v.set_z((get_x() * v1.get_y()) - (get_y() * v1.get_x()));
	v.set_t(1.0);
	return v;
}

Vector Vector::operator+(const Vector &v1) const
{
	Vector v = Vector();
	v.set_x(v1.get_x() + get_x());
	v.set_y(v1.get_y() + get_y());
	v.set_z(v1.get_z() + get_z());
	v.set_t(v1.get_t() + get_t());

	return v;
}

bool Vector::operator==(const Vector &v1) const
{
	return ((v1.get_x()==get_x() && v1.get_y()==get_y() && v1.get_z()==get_z()) && v1.get_t()==get_t());
}

void Vector::operator=(const Vector &v1)
{
	this->set_x(v1.get_x());
	this->set_y(v1.get_y());
	this->set_z(v1.get_z());
	this->set_t(v1.get_t());
}

double Vector::scalar(const Vector &v1) const
{
	return (v1.get_x()*get_x() + v1.get_y()*get_y() + v1.get_z()*get_z() + v1.get_t()*get_t());
}

double Vector::norm()
{
	return (sqrt(get_x()*get_x() + get_y()*get_y() + get_z()*get_z()));
}

void Vector::display() const
{
	cout << "(" << x << "\t " << y << "\t " << z << "\t " << t << ")" << endl;
}

void Vector::normalize()
{
	double n = norm();	
	x /= n;
	y /= n;
	z /= n;
}
